Skip to content

fix(scrapy): dump pydantic models in JSON mode when serializing requests#961

Merged
vdusek merged 3 commits into
masterfrom
fix/scrapy-json-pydantic-models
Jun 12, 2026
Merged

fix(scrapy): dump pydantic models in JSON mode when serializing requests#961
vdusek merged 3 commits into
masterfrom
fix/scrapy-json-pydantic-models

Conversation

@vdusek

@vdusek vdusek commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Pydantic models in a Scrapy request's meta/cb_kwargs were dumped in python mode, so any model with a non-JSON-native field (datetime, UUID, HttpUrl, ...) failed json.dumps and the request was dropped. The v4 upgrade guide promises such models keep working.

  • Dump models with model_dump(mode='json', by_alias=True).
  • Widen the serialization error guards to except (TypeError, ValueError) to cover pydantic's PydanticSerializationError.
  • Add a round-trip test with a datetime-bearing model and update the v4 upgrade guide wording.

A pydantic model in `meta`/`cb_kwargs` with a non-JSON-native field (`datetime`, `UUID`, `HttpUrl`)
failed `json.dumps` and the request was dropped, contradicting the v4 upgrade guide. Also fixes the PyPI
Release Notes URL (pointed at the v2 guide) and stale Python 3.10 claims in the docs.
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Jun 11, 2026
@vdusek vdusek self-assigned this Jun 11, 2026
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.83%. Comparing base (a87e8d1) to head (862f29e).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #961      +/-   ##
==========================================
- Coverage   90.00%   89.83%   -0.18%     
==========================================
  Files          49       49              
  Lines        3053     3090      +37     
==========================================
+ Hits         2748     2776      +28     
- Misses        305      314       +9     
Flag Coverage Δ
e2e 35.92% <0.00%> (+0.25%) ⬆️
integration 56.89% <0.00%> (+0.03%) ⬆️
unit 78.67% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek requested a review from Pijukatel June 11, 2026 12:36
@vdusek vdusek marked this pull request as ready for review June 11, 2026 12:36
@vdusek vdusek requested a review from szaganek as a code owner June 11, 2026 12:36
Comment thread docs/04_upgrading/upgrading_to_v4.md Outdated
@github-actions github-actions Bot added this to the 142nd sprint - Tooling team milestone Jun 12, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Jun 12, 2026
@vdusek vdusek requested a review from Pijukatel June 12, 2026 11:57
@vdusek vdusek merged commit f2ccae1 into master Jun 12, 2026
28 of 29 checks passed
@vdusek vdusek deleted the fix/scrapy-json-pydantic-models branch June 12, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants